﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Configuration;

namespace aspnetmsaccess
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // create an OldDbConnection object and initialize it by passing connection string.
            // ConfigurationManager class provides the ConnectionStrings collection type property
            // to access the connection string stored in the web.config file.
            OleDbConnection myDataConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);

            // open the data connection.
            myDataConnection.Open();

            // display the connection's current state open/closed.
            // Response.Write(string.Format("<i><b>Connection state:</b> {0}</i><br />", myDataConnection.State));

            OleDbCommand dbCommand = new OleDbCommand("Select * FROM Issues", myDataConnection);
            OleDbDataReader dataReader = dbCommand.ExecuteReader();

            GridView1.DataSource = dataReader;
            GridView1.DataBind();

            // close the data connection.
            dataReader.Close();
            myDataConnection.Close();

            // again display the connection's current state open/closed.
            // Response.Write(string.Format("<i><b>Connection state:</b> {0}</i>", myDataConnection.State));

            // dispose the connection object to release the resources.
            myDataConnection.Dispose();
        }
    }
}